var path_name = window.location.pathname;
var $a = $("ul.treeview-menu>li>a[href='" + path_name + "']");
$a.parent("li").addClass("active");
$a.parent("li").parent("ul.treeview-menu").parent("li.treeview").addClass("active");

function clear(obj) {
	$(obj).click(function() {
		location.reload();
	});
}
clear(".close");
clear(".closeBtn");

$("#editpwd").click(function() {
	$('#edit-password').modal('show');
	var error = false;
	var isAdd = true;
	$("#editPassword").validate({
		errorElement : 'span',
		errorPlacement : function(error, element) {
			error.appendTo(element.parent());
		},
		rules : {
			loginPassword:{
				required:true,
			},
			newPassword : {
				required : true,minlength : 6,maxlength : 20,
			},
			newPassword1 : {
				required : true,minlength : 6,maxlength : 20,equalTo : '#newPassword',
			},
		},
		messages : {
			loginPassword : {
				required : "请输入旧密码",
			},
			newPassword : {
				required : "请输入新密码",
				minlength : "密码6-20位",
				maxlength : "密码6-20位",
			},
			newPassword1 : {
				required : "请输入确认密码",
				minlength : "密码6-20位",
				maxlength : "密码6-20位",
				equalTo : "请再次输入相同的值",
			},
		},
		submitHandler : function(form) { // 验证通过后的执行方法
			var url = "../a/editLogPassword";
			var userId = $("input[name=userId]").val();
			var userName = $("input[name=userName]").val();
			var loginName = $("input[name=loginName]").val();
			var loginPassword = $("input[name=loginPassword]").val();
			var newPassword = $("input[name=newPassword]").val();
			$.post(url, {
				userId : userId,
				userName : userName,
				loginName:loginName,
				loginPassword:loginPassword,
				newPassword : newPassword,
			}, function(data) {
				console.log(data);
				if(data.code == 200){
					layer.msg(data.msg, {icon : 1,time : 2500,});
					setTimeout(function(){parent.location.href = '../sys/lougt';}, 2500);
				}else{
					layer.msg(data.msg, {icon : 2,time : 2500,});
				}
				$('#edit-password').modal('toggle');
			},'json');
		},
	});
});